//
//  ZHYiZhanTongChengViewController.m
//  ZhanHui
//
//  Created by 彭超 on 16/5/12.
//  Copyright © 2016年 彭超. All rights reserved.
//

#import "ZHYiZhanTongChengViewController.h"

#import "ZHYiShuQuanViewController.h"
#import "ZHWoYanZhongViewController.h"
#import "ZHShuMaViewController.h"
#import "ZHZiRanViewController.h"
#import "ZHDianPinViewController.h"
#import "ZHHuiZhanViewController.h"

@interface ZHYiZhanTongChengViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@property (nonatomic,strong)UICollectionView *collectionView;


@end

@implementation ZHYiZhanTongChengViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createheadView];
    [self createCollectionView];
    [self createNavigationItem];
}

-(void)createNavigationItem
{
    UIButton*bt=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    [bt addTarget:self action:@selector(clickbutton:) forControlEvents:UIControlEventTouchUpInside];
    [bt setImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:bt];
    self.navigationItem.title=@"";
}

-(void)clickbutton:(UIButton*)button
{
    
}

-(void)createheadView
{
    UIImageView*headview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, ([UIScreen mainScreen].bounds.size.width), ([UIScreen mainScreen].bounds.size.height) * 0.2)];
    headview.image=[UIImage imageNamed:@"hjh"];
    headview.contentMode = UIViewContentModeScaleAspectFit;
    [self.view addSubview:headview];
}

-(void)createCollectionView
{
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, ([UIScreen mainScreen].bounds.size.height) * 0.2, ([UIScreen mainScreen].bounds.size.width), ([UIScreen mainScreen].bounds.size.height)-(([UIScreen mainScreen].bounds.size.height) * 0.2)) collectionViewLayout:flowLayout];
    //设置代理
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.view addSubview:self.collectionView];
    
    self.collectionView.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1];
    
    //注册cell和ReusableView（相当于头部）
    [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"collectionviewcell"];
}

//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 7;
}

//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionviewcell" forIndexPath:indexPath];
    if (indexPath.row==0) {
        UIImageView*cellview=[[UIImageView alloc]init];
        cellview.image=[UIImage imageNamed:@"yishuquan"];
        cell.backgroundView=cellview;
    }
    if (indexPath.row==1) {
        UIImageView*cellview=[[UIImageView alloc]init];
        cellview.image=[UIImage imageNamed:@"yishu"];
        cell.backgroundView=cellview;
    }
    if (indexPath.row==2) {
        UIImageView*cellview=[[UIImageView alloc]init];
        cellview.image=[UIImage imageNamed:@"shuma"];
        cell.backgroundView=cellview;
    }
    if (indexPath.row==3) {
        UIImageView*cellview=[[UIImageView alloc]init];
        cellview.image=[UIImage imageNamed:@"ziran"];
        cell.backgroundView=cellview;
    }
    if (indexPath.row==4) {
        UIImageView*cellview=[[UIImageView alloc]init];
        cellview.image=[UIImage imageNamed:@"zuopin"];
        cell.backgroundView=cellview;
    }
    if (indexPath.row==5) {
        UIImageView*cellview=[[UIImageView alloc]init];
        cellview.image=[UIImage imageNamed:@"huizhan"];
        cell.backgroundView=cellview;
    }
    if (indexPath.row==6) {
        UIImageView*cellview=[[UIImageView alloc]init];
        cellview.image=[UIImage imageNamed:@"kongbai"];
        cell.backgroundView=cellview;
    }
    _collectionView.backgroundColor=[UIColor blackColor];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==1||indexPath.row==2) {
        return CGSizeMake(([UIScreen mainScreen].bounds.size.width-18)/3*2+6, (([UIScreen mainScreen].bounds.size.height)*0.8-128)/3);
    
    }
     return CGSizeMake(([UIScreen mainScreen].bounds.size.width-18)/3,(([UIScreen mainScreen].bounds.size.height)*0.8-128
                                                                       )/3);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    
    //每个元素之间的最小间距，水平方向
    return 6;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    //每个元素之间的最小间距，垂直方向
    return 6;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    //每个单元的内边距
    return UIEdgeInsetsMake(0, 3, 0, 3);
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        ZHYiShuQuanViewController*yishuquanvc=[[ZHYiShuQuanViewController alloc]init];
        [self.navigationController pushViewController:yishuquanvc animated:NO];
    }
    if(indexPath.row==1){
        ZHWoYanZhongViewController*woyanzhongvc=[[ZHWoYanZhongViewController alloc]init];
        [self.navigationController pushViewController:woyanzhongvc animated:NO];
    }
    if (indexPath.row==2) {
        ZHShuMaViewController*shumavc=[[ZHShuMaViewController alloc]init];
        [self.navigationController pushViewController:shumavc animated:NO];
    }
    if (indexPath.row==3) {
        ZHZiRanViewController*ziranvc=[[ZHZiRanViewController alloc]init];
        [self.navigationController pushViewController:ziranvc animated:NO];
    }
    if (indexPath.row==4) {
        ZHDianPinViewController*dianpinvc=[[ZHDianPinViewController alloc]init];
        [self.navigationController pushViewController:dianpinvc animated:NO];
    }
    if (indexPath.row==5) {
        ZHHuiZhanViewController*huizhanvc=[[ZHHuiZhanViewController alloc]init];
        [self.navigationController pushViewController:huizhanvc animated:NO];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
